'''
警告弹窗的常用方法：
(1)switch_to_alert().accept()
(2)switch_to.alert.accept()	建议这个
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

driver = webdriver.Chrome(options=options)
driver.get(r'https://www.baidu.com/')
driver.maximize_window()
sleep(1)

driver.find_element(By.ID, 's-usersetting-top').click()
sleep(1)
driver.find_element(By.LINK_TEXT, '搜索设置').click()
sleep(1)
driver.find_element(By.LINK_TEXT, '保存设置').click()
sleep(3)

# 处理警告弹窗
# 获取本文
text = driver.switch_to.alert.text
print(text)
sleep(2)

# 点击确定
driver.switch_to.alert.accept()
sleep(2)

driver.quit()